<?php

/**
 * @Author: Wang Chunsheng 2192138785@qq.com
 * @Date:   2020-03-01 20:56:37
 * @Last Modified by:   Wang Chunsheng 2192138785@qq.com
 * @Last Modified time: 2020-04-12 19:11:06
 */


use common\addons\diandi_shop\models\GoodsLabel;
use common\models\DdGoods;
use yii\helpers\Html;
use common\widgets\MyActiveForm;
use yii\helpers\ArrayHelper;
use common\components\LevelTpl;
use common\helpers\ImageHelper;
use kartik\file\FileInput;
use yii\helpers\Url;
//use \http\Url;
/* @var $this yii\web\View */
/* @var $model common\models\DdGoods */
/* @var $form yii\widgets\MyActiveForm */
?>

<div class="dd-goods-form">



    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
        <?= $form->field($model, 'goods_name')->textInput(['maxlength' => true]) ?>

        <!--一级目录--> <?= $form->field($model, 'category_pid')->dropDownList($Helper->courseCateMap(), [
                        'prompt' => ['text' => '一级分类', 'options' => ['value' => 0]],
                        'label' => '一级分类',
                        'id' => 'classsearch-cocate_id'
                    ])->label('一级分类') ?>
        <?= $form->field($model, 'goods_price')->textInput() ?>
        <?= $form->field($model, 'stock')->textInput() ?>
        <?= $form->field($model, 'thumb')->widget('manks\FileInput', [])->label('商品主图'); ?>

        <?= $form->field($model, 'goods_status')->radioList([
            '1' => '上架',
            '0' => '下架',
        ], ['style' => 'padding-top:7px;']) ?>
        <?= $form->field($model, 'deduct_stock_type')->radioList([
            '10' => '下单减库存',
            '20' => '支付减库存',
        ], ['style' => 'padding-top:7px;']) ?>
        <?= $form->field($model, 'goods_weight')->textInput() ?>
        <?= $form->field($model, 'delivery_id')->textInput() ?>
        <?= $form->field($model, 'label')->radioList(ArrayHelper::map(
            GoodsLabel::find()->all(),
            'label',
            'label'
        )) ?>
    </div>

    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
        <?= $form->field($model, 'goods_sort')->textInput() ?>

        <!--二级目录--><?= $form->field($model, 'category_id')->dropDownList($Helper->courseMap($model->category_id), [
                        // 'options' => ['5' => ['selected' => true]],
                        'prompt' => ['text' => '二级分类', 'options' => ['value' => 0]],

                        'id' => 'classsearch-course_id'
                    ])->label('二级分类 ') ?>
        <?= $form->field($model, 'line_price')->textInput() ?>
        <?= $form->field($model, 'sales_initial')->textInput() ?>


        <?= $form->field($model, 'images')->widget('manks\FileInput', ['clientOptions' => [
            'pick' => [
                'multiple' => true,
            ]
        ]])->label('商品相册'); ?>
        <?=
            $form->field($model, 'video')->widget(FileInput::classname(), [
                'options' => [
                    'accept' => 'video/mp4',
                    'multiple' => false
                ],
                'pluginOptions' => [
                    'showUpload' => false,
                    'initialPreview' => [ImageHelper::tomedia($model['video'])],
                    'initialPreviewConfig' =>
                    [
                        [
                            'type' => "video",
                            'size' => 375000,
                            'filetype' => "video/mp4",
                            'key' => 15
                        ]

                    ],
                    'initialPreviewAsData' => true,
                    'initialPreviewShowDelete' => true,
                    'fileActionSettings' => [
                        'showRemove' => false,
                    ],
                    'uploadExtraData' => [
                        'field' => 'DdGoods[video]', 'path' => 'goods'
                    ],
                    'allowedPreviewTypes' => ['video'],
                    'maxFileCount' => 1,
                    'theme' => 'explorer-fa',
                    'overwriteInitial' => true,
                    'previewFileType' => 'video/mp4',
                    'uploadAsync' => true,
                    'uploadUrl' => Url::to([
                        '/upload/upload/uploadfile'
                    ])
                ],
                // 一些事件行为
                'pluginEvents' => [
                    // 上传成功后的回调方法，需要的可查看data后再做具体操作，一般不需要设置
                    "fileuploaded" => "function (event, data, id, index) {
                        console.log(data.response.file_path,data)
                        $('input[name=\\'DdGoods[video]\\']').val(data.response.file_path);
                        console.log(data);
                    }",
                ],
            ]);

        ?>



    </div>
</div>